package com.vvkee.customer;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 监听器接口，监听事件抽象基类的所有子类对象
 *
 * @param <E>
 */
public interface VvkeeApplicationListener<E extends VvkeeApplicationEvent> {

    void onApplicationEvent(E event);

    default boolean supportsEventType(VvkeeApplicationEvent event, VvkeeApplicationListener applicationListener) {
        Type[] types = applicationListener.getClass().getGenericInterfaces();
        for (Type type : types) {
            Class clazz = (Class) ((ParameterizedType) type).getActualTypeArguments()[0];
            if (clazz.equals(event.getClass())) {
                return true;
            }
            return false;
        }
        return true;
    }

}
